<?php

namespace app\api\controller\v1;


use app\api\validate\IDCollection;
use app\api\validate\IDMustBePositiveInt;
use app\common\exception\ThemeException;
use app\api\model\Theme as ThemeModel;

class Theme extends Base
{
    /**
     * @url /theme/ids?ids=1,2,3
     *  string $ids=1,2,3
     */
    public function getSimpleList($ids = '')
    {
        (new IDCollection())->goCheck();
        $ids = explode(',', $ids);
        $themes = ThemeModel::getSimpleList($ids);
        if ($themes->isEmpty()) {
            throw new ThemeException();
        }
        return $themes;
    }

    /**
     * @url /theme/id/:id/with_spu
     *  string $id=1
     */
    public function getComplexOne($id)
    {
        (new IDMustBePositiveInt())->goCheck();
        $theme = ThemeModel::getWithProducts($id);
        if (empty($theme)) {
            throw new ThemeException();
        }
        return $theme;
    }
}